package Default;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;

import javax.swing.JPanel;


public class SensorsPanel extends JPanel{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//Environment envi;
	Manager manager;
	int nodeSize;
	//static int cnt=0;
	public SensorsPanel(/*Environment env,*/Manager _manager)
	{
		//envi=env;
		manager=_manager;
		nodeSize=Variables.gridZoom;
		//setBounds(0, 0, 400, 120);
		setPreferredSize(new Dimension(Variables.gridSizeX*nodeSize+nodeSize,Variables.gridSizeY*nodeSize+nodeSize));
		
		}
public void paint(Graphics g)
	{
	setPreferredSize(new Dimension(Variables.gridSizeX*nodeSize+nodeSize,Variables.gridSizeY*nodeSize+nodeSize));
	Point my,to;
	
	
	/*
	g.setColor(Color.yellow);
	int radius=Variables.sense_radius;
	for(int i=0;i<manager.all_agents.size();i++)
	{
		my=manager.all_agents.get(i).position;
		g.fillOval( (my.x-radius+1)*nodeSize, (my.y-radius+1)*nodeSize, radius*nodeSize*2, radius*nodeSize*2);
		
	}
	*/
	/*if(manager.agent!=null)
	{
		g.setColor(Color.black);
		
		g.drawOval(manager.agent.position.x*nodeSize, manager.agent.position.y*nodeSize, 8, 8);
		g.setColor(Color.red);
		if(manager.agent.ID!=0)
			g.drawOval(manager.agent.connect.connectTo.position.x*nodeSize, manager.agent.connect.connectTo.position.y*nodeSize, 8, 8);
	//System.out.println(manager.all_agents.get(5).connect.connectTo.ID);
	}*/
	
	
	//g.setColor(Color.red);
	for(int i=0;i<Variables.gridSizeY;i++)
	{
		for(int j=0;j<Variables.gridSizeX;j++)
		{
			if(Variables.grid[i][j]>0)
			{
				g.setColor(manager.all_agents.get(Variables.grid[i][j]-1).myColor);
				g.fillOval(j*nodeSize+nodeSize/2, i*nodeSize+nodeSize/2, nodeSize, nodeSize);
			}
			else if(Variables.grid[i][j]<0)
			{
				g.setColor(Color.black);
				g.fillOval(j*nodeSize+nodeSize/2, i*nodeSize+nodeSize/2, nodeSize+1, nodeSize+1);
				g.setColor(Color.red);
			}
		}
	}
	
	g.setColor(Color.blue);
	int sum=0;
	for(int i=0;i<manager.all_agents.size();i++)
	{
		my=manager.all_agents.get(i).position;
		to=manager.all_agents.get(i).connect.connectTo.position;
		g.drawLine(my.x*nodeSize+nodeSize, my.y*nodeSize+nodeSize, to.x*nodeSize+nodeSize, to.y*nodeSize+nodeSize);
		sum+=manager.all_agents.get(i).connect.numOfMessege;
		
	}
	
	
	g.setColor(Color.GRAY);
	g.drawRect(Variables.sense_radius*nodeSize,Variables.sense_radius*nodeSize , Variables.x*nodeSize, Variables.y*nodeSize);
	g.drawOval((Variables.gridSizeX/2-Variables.sense_radius*2)*nodeSize, (Variables.gridSizeY/2-Variables.sense_radius*2)*nodeSize,/*48,48*/ (Variables.sense_radius*4+2)*nodeSize, (Variables.sense_radius*4+2)*nodeSize);
	
	/*if(manager.target!=null)
	{
		g.setColor(Color.magenta);
		g.drawLine(manager.target.start.x, manager.target.start.y, manager.target.end.x, manager.target.end.y);
		g.setColor(Color.black);
		g.fillOval(manager.target.location.y, manager.target.location.x, 4, 4);
	}*/
	g.setColor(Color.blue);
	Agent agent=null;

		/*agent=manager.all_agents.get(92);
		g.drawOval(agent.position.x*nodeSize, agent.position.y*nodeSize, 8, 8);
		agent=manager.all_agents.get(51);
		g.drawOval(agent.position.x*nodeSize, agent.position.y*nodeSize, 8, 8);
		agent=manager.all_agents.get(13);
		g.drawOval(agent.position.x*nodeSize, agent.position.y*nodeSize, 8, 8);
	*/
	
	
	g.setColor(Color.black);
	agent=null;
	for(int i=0;i<manager.all_agents.size();i++)
	{
		agent=manager.all_agents.get(i);
		if(agent.senseVol>0)
		g.drawOval(agent.position.x*nodeSize, agent.position.y*nodeSize, 8, 8);
		
	}
	
	g.setColor(Color.red);
	agent=null;
	for(int i=0;i<manager.all_agents.size();i++)
	{
		agent=manager.all_agents.get(i);
		if(agent.battery>=Variables.battery_Size)
		g.drawOval(agent.position.x*nodeSize, agent.position.y*nodeSize, 8, 8);
		
	}
	
	
	
	}

	
	
}
